package com.wm.practice;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @ClassName: CompletableFutrueDemo
 * @Description: 异步多线程
 * @Author: Deamer
 * @Date: 2022/8/28 9:22
 **/
public class FutureTaskDemo {
    public static void main(String[] args) {
        // 异步任务、多线程、返回值
        FutureTask<String> futureTask = new FutureTask<>(new MyThread());
        Thread t1 = new Thread(futureTask, "t1");
        t1.start();
        try {
            // 接收返回值
            System.out.println(futureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}

class MyThread implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println("........come in call ------异步执行");
        return "hello Callable 返回值";
    }
}
